<?php 
	@session_start();
	include("../connect/connect_mysql.php");
	$id = $_GET['id'];
?>
<link rel="stylesheet" href="../css/content.css" type="text/css" />
<link rel="stylesheet" href="../css/ui/jquery.ui.datepicker.css" type="text/css" />

<script type="text/javascript">
	Ext.onReady(function(){
		var id= "<?php echo $id ?>";
		
		$('#edit_event').click(function(){
			var p=$('#group').val(); 
			var d=$('#datepicker').val();
			var n = $('#name_event').val().trim();
			var i=$('#info').val().trim();
			Ext.Ajax.request({
				url:  'services/event.php',
				method: 'POST',
				params: {act :'edit_event',
						 id: id,
						 time: p,
						 name_event : n,
						 date: d,
						 info: i},
				success: function (result, request){
					if(result.responseText == 1){
						alert("Thay đổi thành công");
						document.location = "?act=event";
					}
				},
				failure: function ( result, request ) {
					alert("Có lỗi khi kết nối cơ sở dữ liệu");
    			}
			});
		});
		Ext.Ajax.request({
			url:  'services/event.php',
			method: 'POST',
			params: {act : 'innit',
					 id : id},
			success: function ( result, request ) {
				var arr = result.responseText;
				arr =arr.split('}#');
				for(var i=0;i<arr.length;i++){
					arr[i]=arr[i].replace('{','');
					arr[i]=arr[i].replace('}','');
					arr[i]=arr[i].replace(/\.-/g,'\n');
					arr[i]=arr[i].split('#');
				}
				$("#name_event").val(arr[0][3]);
				$("#group").find("option[value="+ arr[0][2] + "]").attr("selected", "selected");
				$("#datepicker").val(arr[0][1]);
				$("#info").val(arr[0][5]);
			}
		});
        $( "#datepicker" ).datepicker({
			showOn: "button",
			buttonImage: "../images/calendar.gif",
			buttonImageOnly: true,
			dateFormat: 'yy/mm/dd'		
		});

		$('#cancelcontent').click(function(){
			if(confirm("Bạn không muốn thay đổi?")){
				window.history.back();
			}
		});
	});
</script>
	<div id="wrapper">
		<form id="form" method="POST" action="">
			<fieldset>
				<legend>Edit Content</legend>				
				<table id="event-table">
				<tr>
					<td>Ngày</td>
					<td>
                        <input id="datepicker" name="date" type="text" value="<?php echo date("Y/m/d"); ?>" readonly="true" />
					</td>
				</tr>
				<tr>
					<td>Buổi</td>
					<td><select name="group" id="group">
							<option value="0">Sáng</option>
							<option value="1" >Trưa</option>
							<option value="2" selected="sellected" >Chiều</option>
							<option value="3">Tối</option>
					</select></td>
				</tr>
				<tr>
					<td>Tên&nbsp;Sự&nbsp;Kiện</td>
					<td><input type="text" id="name_event" value="Sinh nhật" /></td>	
				</tr>
				<tr>
					<td style="padding-bottom: 170px;">Nội&nbsp;Dung</td>
					<td><textarea cols="40" rows="10" id="info"></textarea>
					</td>
				</tr>
				</table>
				<div>
					<input type="button" id="edit_event" value="Update&nbsp;Event" class="button" />
					<input type="button" id="cancelcontent" value="Cancel" class="button" />
				</div>			
			</fieldset>
		</form>
	</div><!--end wrapper-->